package com.android.love.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class CustomViewPager extends ViewPager {

	private onMoveAndUpListener mMoveUpListener;

	public static interface onMoveAndUpListener {

		public abstract void onMove();

		public abstract void onUp();
	}

	public CustomViewPager(Context context) {
		super(context);
	}

	public CustomViewPager(Context context, AttributeSet attributeset) {
		super(context, attributeset);
	}

	public boolean onInterceptTouchEvent(MotionEvent motionevent) {
		getParent().requestDisallowInterceptTouchEvent(true);
		return super.onInterceptTouchEvent(motionevent);
	}

	public boolean onTouchEvent(MotionEvent motionevent) {

		switch (motionevent.getAction()) {
		case MotionEvent.ACTION_DOWN:
		case MotionEvent.ACTION_MOVE:
			if (this.mMoveUpListener != null)
				this.mMoveUpListener.onMove();
			break;
		case MotionEvent.ACTION_UP:
			if (this.mMoveUpListener != null)
				this.mMoveUpListener.onUp();
			break;
		default:
			if (this.mMoveUpListener != null)
				this.mMoveUpListener.onUp();
			break;
		}
		return super.onTouchEvent(motionevent);
	}

	public void setMoveAndUpListener(onMoveAndUpListener onmoveanduplistener) {
		mMoveUpListener = onmoveanduplistener;
	}

}
